public class 数字数组最大值 {
    /**
     * 123
     * 654
     * ==654123
     * 123 12
     * 12312
     * 12123（小）
     * 321 32
     * 32132（小）
     * 32321
     * 34 345
     * 34345
     * 34534
     * @param args
     */
    public static void main(String[] args) {
        // int[] input = {654,123,45,89};
        int[] input = {32,321};
        int[] output;
        output = fun1(input);
        System.out.println("output");
        for (int i = 0; i < output.length; i++) {
            System.out.print(output[i]+"\t");
        }
        System.out.println();
        System.out.println("input");
        for (int i = 0; i < input.length; i++) {
            System.out.print(input[i]+"\t");
        }
    }

    /**
     * 每一个数字乘以权值，表示出一个最大数字
     * @param input
     * @return
     */
    public static int[] fun1(int[] input) {
        System.out.println("123： "+input.toString());
        // String[] number = input.toString();
int[] output = new int[5];
        return output;
    }
    /**
     * 数字都表示成相同位数，比较大小即可,同步映射成原始数组的排序
     */
    public static int[] fun2(int[] input) {
        int maxlen = 0;
        int[] length = new int[input.length]; // 先存储位数，后存储排序值
        // 求每一位数字的长度
        for (int i = 0; i < input.length; i++) {
            int len = 0, a = input[i];
            while (a > 0){
                len++;
                a /= 10;
            }
            length[i] = len;
            maxlen = Math.max(maxlen, len);
        }
        System.out.println("length: ");
        for (int i = 0; i < length.length; i++) {
            System.out.print(length[i]+"\t");
        }
        System.out.println();
        System.out.println("maxlen: "+maxlen);
        // 根据最大长度，补齐每一位数字
        /**
         * 特殊情况，321 和 32 比较的话，即相同前缀
         */
        for (int i = 0; i < length.length; i++) {
            if(length[i] == maxlen){
                length[i] = input[i];
            }else {
                int a = 0,b=1;
                for (int j = 0; j < (maxlen-length[i]); j++) {
                    a = a*10+9;
                    b = b*10;
                }
                if(input[i]%10 > (input[i]%100)%10)
                length[i] = input[i]*b + a;
            }
        }
        for (int i = 0; i < length.length; i++) {
            System.out.println(length[i]);
        }
        return quickSortArrayOneDimensional(input,length,0, input.length-1);
    }
    // 重小到大排序
    public static int[] quickSortArrayOneDimensional(int[] array,int[] length,int start, int end){
        int pivot = length[start];
        int i = start;
        int j = end;
        while (i<j) {
            while ((i<j)&&(length[j]>pivot)) {
                j--;
            }
            while ((i<j)&&(length[i]<pivot)) {
                i++;
            }
            if ((length[i]==length[j])&&(i<j)) {
                i++;
            } else {
                int temp1 = length[i];
                length[i] = length[j];
                length[j] = temp1;
                int temp2 = array[i];
                array[i] = array[j];
                array[j] = temp2;
            }
        }
        if (i-1>start)
            array=quickSortArrayOneDimensional(array,length,start,i-1);
        if (j+1<end)
            array=quickSortArrayOneDimensional(array,length,j+1,end);
        return array;
    }
}
